﻿<%@ page language="java" import="com.demo.util.Conn,java.sql.ResultSet,java.util.Calendar,java.text.SimpleDateFormat" pageEncoding="UTF-8"%>
<%
String cname = request.getParameter("companyname");
String jtitle = request.getParameter("jtitle");
String jsd = request.getParameter("jsd");

String pageNum = request.getParameter("page");
pageNum = "".equals(pageNum) || pageNum == null ? "1" : pageNum;
int pageSize = 20;

String sql = " from dbf_job_info where 1=1 ";
if (!"".equals(cname) && cname != null)
	sql = sql + " and company_name like '" + cname + "%'";
if (!"".equals(jtitle) && jtitle != null) 
	sql = sql + " and job_title like'" + jtitle + "%'";
if (!"".equals(jsd) && jsd != null && !" ".equals(jsd)) {
	Calendar cal = Calendar.getInstance();
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	cal.add(cal.DATE,Integer.valueOf(jsd).intValue());
	
	sql = sql + " and job_starting_date >= '" + sdf.format(cal.getTime()).trim() + "'";
}

String sqlCount = "select count(*) as cnt " + sql;
sql = "select * " + sql + " limit " + (Integer.valueOf(pageNum).intValue() - 1) * pageSize + "," + pageSize;

Conn conn = new Conn();
ResultSet rs = conn.find(sqlCount);
rs.next();
int count = rs.getInt("cnt");
rs.close();
rs = conn.find(sql);
cname = cname == null ? "" : cname;
jtitle = jtitle == null ? "" : jtitle;
jsd = jsd == null ? "" : jsd;
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>职位搜索</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<link rel="stylesheet" type="text/css" href="../style.css">
  </head>
  
  <body>
  <table width="718" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td height="39" colspan="3" background="../images/main_title.jpg"><strong>&nbsp;&nbsp;&nbsp;&nbsp;<span class="menutitle">&nbsp;Search</span></strong></td>
    </tr>
    <tr>
      <td valign="bottom"><img src="../images/menu_a.jpg" width="19" height="23" /></td>
      <td valign="top">&nbsp;</td>
      <td valign="bottom"><img src="../images/menu_b.jpg" width="18" height="23" /></td>
    </tr>
    <tr>
      <td width="19" valign="top" background="../images/menu_c.jpg"><img src="../images/menu_c.jpg" width="19" height="54" /></td>
      <td width="681" valign="top"><form action="psearch.jsp">
  				<table border="0" cellspacing="0" cellpadding="0" style="width:100%">
  					<tr class="logintxt">
  						<td colspan="5" style="text-align:right">
  							Total <%=count %> Record(s)&nbsp;&nbsp;&nbsp;&nbsp;
  							<%="1".equals(pageNum) ? "First" : "<a href=\"psearch.jsp?page=1&companyname=" + cname + "&jtitle=" + jtitle + "&jsd=" + jsd + "\">First Page</a>" %>&nbsp;&nbsp;
  							<%="1".equals(pageNum) ? "Previous" : "<a href=\"psearch.jsp?page=" + String.valueOf(Integer.valueOf(pageNum).intValue() - 1) + "&companyname=" + cname + "&jtitle=" + jtitle + "&jsd=" + jsd + "\">Previous</a>" %>&nbsp;&nbsp;
  							<%=((Integer.valueOf(pageNum).intValue() * pageSize)) < count ? "<a href=\"psearch.jsp?page=" + String.valueOf(Integer.valueOf(pageNum).intValue() + 1) + "&companyname=" + cname + "&jtitle=" + jtitle + "&jsd=" + jsd + "\">Next</a>" : "Next" %>&nbsp;&nbsp;
  							<%=((Integer.valueOf(pageNum).intValue() * pageSize)) >= count ? "Last" : "<a href=\"psearch.jsp?page=" + (count % pageSize == 0 ? count / pageSize : count / pageSize + 1) + "&companyname=" + cname + "&jtitle=" + jtitle + "&jsd=" + jsd + "\">Last</a>" %>  						</td>
  					</tr>
  					<tr><td colspan="5" height="5"></td></tr>
  					<tr>
                      <th width="23%" class="style4" style="background-color:#FFC963">Company</th>
  					  <th width="20%" class="style4" style="background-color:#FFC963">Post</th>
  					  <th width="19%" class="style4" style="background-color:#FFC963">Start Date</th>
  					  <th width="16%" class="style4" style="background-color:#FFC963">End Date</th>
  					  <th width="22%" class="style4" style="background-color:#FFC963">Available</th>
				  </tr>
  					<%
  						while(rs.next()) {
  					%>
  						<tr>
  							<td class="logintxt"><%=rs.getString("company_name")==null ? "" : rs.getString("company_name") %></td>
  							<td class="logintxt"><a href="job_info.jsp?job_id=<%=rs.getString("JOB_ID") %>"><%=rs.getString("job_title")==null ? "" : rs.getString("job_title") %></a></td>
  							<td class="logintxt"><%=rs.getString("job_starting_date")==null ? "" : rs.getString("job_starting_date") %></td>
  							<td class="logintxt"><%=rs.getString("application_deadline")==null ? "" : rs.getString("application_deadline") %></td>
  							<td class="logintxt"><%=rs.getString("persion_num")==null ? "" : rs.getString("persion_num") %></td>
  						</tr>
  					<%} %>
  					<tr><td colspan="5" height="20">&nbsp;</td></tr>
  					<tr>
  						<td colspan="5">
  							<table border="0" cellspacing="0" cellpadding="0" style="width:100%">
  								<tr>
  									<td align="right" class="logintxt">Company：</td>
  									<td align="left" class="logintxt"><input name="companyname" type="text" class="logintxt" /></td>
  									<td align="right" class="logintxt">Post Date ：</td>
  									<td align="left" class="logintxt">
  										<select name="jsd" class="logintxt" id="jsd">
  											<option value=" ">--Please Select--</option>
  											<option value="-1">--1 Day--</option>
  											<option value="-7">--1 Week--</option>
  											<option value="-30">--1 Month--</option>
  										</select>  									</td>
  									<td align="right" class="logintxt">Job：</td>
  									<td align="left" class="logintxt"><input name="jtitle" type="text" class="logintxt" />&nbsp;&nbsp;&nbsp;&nbsp;
								    <input name="image" type="image" value="search" src="../images/search_btn.jpg" /></td>
  								</tr>
  							</table>  						</td>
  					</tr>
  				</table>
  				</form></td>
      <td width="18" valign="top" background="../images/menu_d.jpg"><img src="../images/menu_d.jpg" width="18" height="54" /></td>
    </tr>
    <tr>
      <td><img src="../images/menu_e.jpg" width="19" height="25" /></td>
      <td background="../images/menu_f.jpg"><img src="../images/menu_f.jpg" width="181" height="25" /></td>
      <td><img src="../images/menu_g.jpg" width="18" height="25" /></td>
    </tr>
  </table>
  </body>
</html>
